///////////////////////////////////////////////////
// Election Administration Polarization
// Joint Policy RD Table, Republican Counties Only
///////////////////////////////////////////////////

gl path "~/Library/CloudStorage/GoogleDrive-danmckinleythompson@gmail.com/My Drive/ElecAdminPolarization/How_Partisan_Is_Local_Election_Admin_Replication"

* Bring in the turnout and registration analysis data
use "$path/analysis_data/rd_reg_turnout_analysis_data.dta", clear

// Polling places
rdrobust r_eavs_polling_places_per1k rv if lag_vs_dem<0.5, vce(cluster election_id)
rdtab r_eavs_polling_places_per1k treat rv election_id, est_command("rdrobust") new("R")
sum eavs_polling_places_per1k if lag_vs_dem<0.5
local m1_r = r(mean)

// Provisionals
rdrobust r_prov_rate rv if lag_vs_dem<0.5, vce(cluster election_id)
rdtab r_prov_rate treat rv election_id, est_command("rdrobust") old("R")
sum prov_rate if lag_vs_dem<0.5
local m2_r = r(mean)

// Provisionals rejected
rdrobust r_prov_rejection_rate rv if lag_vs_dem<0.5, vce(cluster election_id)
rdtab r_prov_rejection_rate treat rv election_id, est_command("rdrobust") old("R")
sum prov_rejection_rate if lag_vs_dem<0.5
local m3_r = r(mean)

// Absentee rejection rate
rdrobust r_eavs_absentee_rej_rate rv if lag_vs_dem<0.5, vce(cluster election_id)
rdtab r_eavs_absentee_rej_rate treat rv election_id, est_command("rdrobust") old("R")
sum eavs_absentee_rej_rate if lag_vs_dem<0.5
local m4_r = r(mean)

// Registration
rdrobust r_registered_pc rv if lag_vs_dem<0.5, vce(cluster election_id)
rdtab r_registered_pc treat rv election_id, est_command("rdrobust") old("R")
sum registered_pc if lag_vs_dem<0.5
local m5_r = r(mean)

// Registration removal rate
rdrobust r_eavs_reg_removal_rate rv if lag_vs_dem<0.5, vce(cluster election_id)
rdtab r_eavs_reg_removal_rate treat rv election_id, est_command("rdrobust") old("R")
sum eavs_reg_removal_rate if lag_vs_dem<0.5
local m6_r = r(mean)

// Dem registration share
rdrobust r_reg_dem_share rv if lag_vs_dem<0.5, vce(cluster election_id)
rdtab r_reg_dem_share treat rv election_id, est_command("rdrobust") old("R")
sum reg_dem_share if lag_vs_dem<0.5
local m7_r = r(mean)

// Wait times r_wait_over30
rdrobust r_wait_over30 rv if lag_vs_dem<0.5, vce(cluster election_id)
rdtab r_wait_over30 treat rv election_id, est_command("rdrobust") old("R")
sum wait_over30 if lag_vs_dem<0.5
local m8_r = r(mean)

** table on republican majority counties
qui {
* Build the memo/paper table
cap log close
set linesize 255
log using "$path/output/rd_table_policy_republican.tex", text replace
noi di "\begin{table}[t]"
noi di "\centering"
noi di "\caption{\textbf{Effect of Democratic Election Officials on Policies and More Proximate Outcomes (Republican Majority Counties Only).}"
noi di "\label{tab:rd_table_policy_republican}}"
noi di "\begin{tabular}{lcccccccc}"
noi di "\toprule \toprule"
noi di " & Polling 	& Prov		& Prov		& Absentee	& Reg	& Reg		& Dem Reg 	& Wait  \\"
noi di " & Places	& Share		& Rejection	& Rejection	& Rate	& Removal	& Share		& Share \\"
noi di " & (1)		& (2)		& (3)		& (4)		& (5)	& (6)		& (7)		& (8)   \\"
noi di "\midrule"
noi di "Dem Elec Official & " %4.3f R[1,1] " & " %4.3f R[1,2] " & " %4.3f R[1,3] " & " %4.3f R[1,4] " "
noi di 		" & " %4.3f R[1,5] " & " %4.3f R[1,6] " & " %4.3f R[1,7] " & " %4.3f R[1,8] "\\"
noi di " & (" %4.3f R[2,1] ") & (" %4.3f R[2,2] ") & (" %4.3f R[2,3] ") & (" %4.3f R[2,4] ") "
noi di 		" & (" %4.3f R[2,5] ") & (" %4.3f R[2,6] ") & (" %4.3f R[2,7] ") & (" %4.3f R[2,8] ") \\[2mm]"
noi di "\midrule"
noi di "N & " %4.0f R[3,1] " & " %4.0f R[3,2] " & " %4.0f R[3,3] " & " %4.0f R[3,4] " "
noi di 	" & " %4.0f R[3,5] " & " %4.0f R[3,6] " & " %4.0f R[3,7] " & " %4.0f R[3,8] " \\ "
noi di "Clusters & " %4.0f R[4,1] " & " %4.0f R[4,2] " & " %4.0f R[4,3] " & " %4.0f R[4,4] " "
noi di 	" & " %4.0f R[4,5] " & " %4.0f R[4,6] " & " %4.0f R[4,7] " & " %4.0f R[4,8] " \\ "
noi di "Outcome Mean & " %4.3f `m1_r' " & " %4.3f `m2_r' " & " %4.3f `m3_r' " & " %4.3f `m4_r' " "
noi di 	" & " %4.3f `m5_r' " & " %4.3f `m6_r' " & " %4.3f `m7_r' " & " %4.3f `m8_r' " \\ "
noi di "Bandwidth & " %4.2f R[5,1] " & " %4.2f R[5,2] " & " %4.2f R[5,3] " & " %4.2f R[5,4] " "
noi di 	" & " %4.2f R[5,5] " & " %4.2f R[5,6] " & " %4.2f R[5,7] " & " %4.2f R[5,8] " \\ "
noi di "BW Selection & CCT & CCT & CCT & CCT & CCT & CCT & CCT & CCT \\"
noi di "Kernel & Tri & Tri & Tri & Tri & Tri & Tri & Tri & Tri \\"
noi di "\bottomrule \bottomrule"
noi di "\multicolumn{9}{p{1.1\textwidth}}{\footnotesize Robust standard errors clustered by clerk election in parentheses. "
noi di "The outcome is first regressed on a state- and year-specific lag using all counties including those for which clerk election "
noi di "results are not available. The regression discontinuity is estimated using the residuals from that regression. "
noi di "The bandwidth row reports the number of maximum clerk win margin allowed for inclusion in each specificaiton. "
noi di "CCT refers to \cite{calonico2014robust} bandwidth selection procedure."
noi di "Tri refers to a triangular kernel."
noi di "Republican counties are those in which the Democratic clerk candidate's vote share is less than 0.50.}"
noi di "\end{tabular}"
noi di "\end{table}"
log off
}
